package com.design.composite.file;

public class CompositeDemo {
    public static void main(String[] args) {
        // 创建文件
        File file1 = new File("file1.txt", 100);
        File file2 = new File("file2.txt", 200);

        // 创建目录
        Directory dir1 = new Directory("dir1");
        dir1.addNode(file1);
        dir1.addNode(file2);

        File file3 = new File("file3.txt", 150);
        File file4 = new File("file4.txt", 250);

        Directory dir2 = new Directory("dir2");
        dir2.addNode(file3);
        dir2.addNode(file4);

        // 创建更高层级的目录
        Directory rootDir = new Directory("root");
        rootDir.addNode(dir1);
        rootDir.addNode(dir2);

        // 显示文件系统结构
        System.out.println("File System Structure:");
        rootDir.display();

        // 计算总文件大小
        long totalSize = rootDir.getSize();
        System.out.println("\nTotal Size of File System: " + totalSize + " bytes");
    }
}
